﻿<html>
<head>
    <title>驰骋工作流</title>
    <link href="../Scripts/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="../Scripts/bootstrap/bootstrap-table/src/bootstrap-table.css" rel="stylesheet"
        type="text/css" />

    <script type="text/javascript" src="../Scripts/bootstrap/js/jquery.min.js"></script>
    <script src="../Scripts/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
    <link href="../Scripts/bootstrap/bootstrap-paginator/css/bootstrapv3.css" rel="stylesheet"
        type="text/css" />
    <link href="../Scripts/bootstrap/DatePicker/bootstrap-datepicker.min.css" rel="stylesheet"
        type="text/css" />
    <script src="../Scripts/bootstrap/bootstrap-paginator/js/bootstrap-paginator.js"
        type="text/javascript"></script>
    <script src="../Scripts/bootstrap/BootstrapUIDialog.js" type="text/javascript"></script>
    <script src="../Scripts/bootstrap/bootstrap-table/src/bootstrap-table.js" type="text/javascript"></script>
    <script src="../Scripts/bootstrap/bootstrap-table/src/locale/bootstrap-table-zh-CN.js" type="text/javascript"></script>
    <script src="../Scripts/bootstrap/DatePicker/bootstrap-datepicker.min.js" type="text/javascript"></script>
    <script src="../Scripts/bootstrap/DatePicker/bootstrap-datepicker.zh-CN.min.js" type="text/javascript"></script>
    <script src="../Scripts/QueryString.js" type="text/javascript"></script>
    <!-- 引用通用的js文件. -->
    <script type="text/javascript" src="../Scripts/config.js"></script>
    <script type="text/javascript" src="../Comm/Gener.js"></script>
    <script src="../../DataUser/JSLibData/CCFormRef.js" type="text/javascript"></script>
    <script src="../Comm/JS/Calendar/WdatePicker.js" type="text/javascript"></script>
    <link rel="stylesheet" type="text/css" href="../Comm/JS/Calendar/skin/WdatePicker.css" />
    <style type="text/css">
        .keyWordInput
        {
            border-top-right-radius: 5px;
            border-top-left-radius: 5px;
            border-bottom-right-radius: 5px;
            border-bottom-left-radius: 5px;
            height: 30px;
        }
        .menuGroup
        {
            float: left;
        }
        .menuGroup a
        {
            margin-left:10px;
        }
        .menuGroupSelected
        {
            color: Blue; /* 文字颜色 */
            font-weight: bold;
            text-decoration: none;
            padding-bottom:5px;
            border-bottom: 3px solid Blue;
        }
        .searchpanellabel
        {
            font-size:13px;
            margin-left:5px;
            margin-right:5px;
        }
        #searchDiv
        {
            padding-top:5px;
            padding-bottom:5px;
        }
       .Wdate
       {
           height:34px;
       }
        .fixed-table-body{
            overflow-y:hidden;
        }
    </style>
    <script type="text/javascript" language="javascript">
        //扩展设置信息
        var mapExt = null;
        //查询条件集合
        var condtionsArry = [];
        //查询条件，按照条件字段长度排序后
        var condtionFieldsArry = [];
        //页面启动函数.
        $(function () {
            //重置页面内容
            ResetHtml();
            //实体参数.
            var ensName = GetQueryString("EnsName");
            mapExt = new Entity("BP.Sys.MapExt");
            //mapExt.ExtType = "BillModel";
            mapExt.MyPK = "DtlImp_" + ensName +"_BillModel";
            var i = mapExt.RetrieveFromDBSources();
            if (i == 0) {
                alert("没有配置导入数据相关参数。");
                return;
            }

            var searchSQL = mapExt.Tag2;
            if (searchSQL == null || searchSQL == "") {
                alert("没有查询SQL，请联系管理员");
                return;
            }
            if (searchSQL.indexOf("@Key") == -1) {
                alert("配置的查询SQL中查询条件必须包含关键字Key，请联系管理员");
                return;
            }

            var html = "";
            if (searchSQL.indexOf("@DTFrom") != -1 && searchSQL.indexOf("@DTTo") != -1) {
                var defVal = new Date();
                defVal = FormatDate(defVal, "yyyy-MM-dd");
                html += "<label style='font-weight: inherit;'>时间从</label>&nbsp<input type=text id='TB_DTFrom' name='TB_DTFrom' value='" + defVal + "'  onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd'})\" style='width:120px;display:inline' class='form-control Wdate' />";
                html += "&nbsp;&nbsp;<label  style='font-weight: inherit;'>到</label>&nbsp;&nbsp<input type=text id='TB_DTTo' name='TB_DTTo' value='" + defVal + "'  onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd'})\" style='width:140px;display:inline' class='form-control Wdate' />";
                $("#search_btn").before(html);
            }

            //关键字输入提示
            var SearchTip = mapExt.GetPara("SearchTip");
            if (SearchTip == undefined) {
                SearchTip = "请输入关键字进行搜索";
            }

            $("#TB_Key").attr("placeholder", SearchTip);
            $('#TB_Key').bind('keypress', function (event) {
                if (event.keyCode == 13)
                    Search();
            });

            $('#DalogModelOK1').bind('click',function(){
                $('#msgModal').modal('hide');
            });
            //输入关键字查询数据
            Search();
            //设置表格内容高度
            SetTableSize();
        });

        //设置表格高度
        function SetTableSize() {
            var height = $(window).innerHeight();
            height = height - 100;
            //表格内容高度
            $("#tableContent").height(height);
        }

       
        //输入关键字进行查询
        function Search() {
            var data = null;
            var UserNo = GetQueryString("UserNo");
            var RefPKVal = GetQueryString("RefPKVal");
            var keyWord = $("#TB_Key").val();
            var DTFrom = $("#TB_DTFrom").val();
            var DTTo = $("#TB_DTTo").val();
            var dbSrc = mapExt.Tag2;
            var reg = new RegExp("@Key", "g");
            dbSrc = dbSrc.replace(reg, keyWord);
            dbSrc = dbSrc.replace("@DTFrom", DTFrom);
            dbSrc = dbSrc.replace("@DTTo", DTTo);
            //处理SQL
            //替换表达式常用的用户信息
            var webUser = new WebUser();
            dbSrc = dbSrc.replace('@WebUser.No', webUser.No);
            dbSrc = dbSrc.replace('@WebUser.Name', webUser.Name);
            dbSrc = dbSrc.replace("@WebUser.FK_DeptNameOfFull", webUser.FK_DeptNameOfFull);
           dbSrc = dbSrc.replace('@WebUser.FK_DeptName', webUser.FK_DeptName);
            dbSrc = dbSrc.replace('@WebUser.FK_Dept', webUser.FK_Dept);
            data = DBAccess.RunDBSrc(dbSrc, mapExt.DBType);

            $("#jsonDataTable").html("");
            if (data && data.length > 0) {
                InitTableByData(data);
            }
        }

        //数据返回Table
         var refpk ="";
        function InitTableByData(dataTable) {
            //获取数据列名
            var columns = [];


            var texts = [];
            var heads = [];
           
            if (mapExt.Tag3.length > 0) {
                texts = mapExt.Tag3.split(',');
            }
            for (var col in dataTable[0]) {
                columns.push(col);
            }

            refpk = columns[0];
            heads.push({ checkbox: true, width: 1, 
                  cellStyle: {css: { "width": "1px" } }
                });
            //以中文个数为表格显示列的个数
            if (texts && texts.length > 0) {
                $.each(texts, function (i, column) {
                    if (column == "")
                        return;
                    var columns = column.split("=");
                    if (columns.length == 2) {
                        var column = {};
                        column.No = columns[0];
                        column.Name = columns[1];
                        heads.push({
                            field: columns[0],
                            title:  columns[1],
                        });
                    }
                });
            } else {
                $.each(columns, function (i, col) {
                    var column = {};
                    column.No = col;
                    column.Name = col;
                    heads.push({
                            field: col,
                            title: col,
                        });
                });
            }

            //单选还是多选
            var selectType = mapExt.GetPara("SelectType");
            var checkbox = selectType == "0" ? true : false;

            $('#jsonDataTable').bootstrapTable({
                data: dataTable,
                columns: [heads],
                cache:false,
                striped: true,
                clickToSelect:true,
                singleSelect: checkbox,
                sidePagination: "server",
                pageNumber: 1,
                strictSearch: true,
                onDblClickRow: function (row, $element) {
                    if(checkbox == true)
                        BootStrapDialog(row[refpk]);
                },
                onCheck:function (row) {
                   if(checkbox == true)
                        BootStrapDialog(row[refpk]);
                }

            });
          }  

        //重置标签
        function ResetHtml() {
            $("#groupDiv").html("");
            $("#jsonDataTable").html("");
        }
        function SelectTr(obj) {
            $.each($(":checkbox"), function () {
                this.checked = false;
            });
             
        }

        //选中行或者选中复选框时弹出从表页面
        function BootStrapDialog(refPK) {
            var url = window.location.href;
            url = url.replace("DtlImpByBill.htm", "DtlImpByBillDtl.htm");
            if (url.indexOf("#") != -1)
                url = url.replace("#", "");
            url = url + "&RefPK=" + refPK;
            //$('#iframeDtl').attr('src', url);
            //$('#msgModal').modal().show();
            var digWidth = document.body.clientWidth-80;;
            var digHeight = document.body.clientHeight-120;
             OpenBootStrapModal(url, "dtlIFrame", "明细表查询", digWidth, digHeight, "icon-edit", false, function () { }, null, function () {
                location = location;
            },"msgModal");
        }

       function BtnOK(){
        //获取选择的主表
         var data = $("#jsonDataTable").bootstrapTable('getSelections');
         if(data.length == 0){
            alert('没有选择任何行数据');
            return;
         }

         var pkVals = "";
         $.each(data,function(i,obj){
            pkVals += obj[refpk]+",";
         });
        BootStrapDialog(pkVals);
       }
        //取消，关闭弹出层
        function DalogModelCose() {
            if (window.parent && window.parent.CloseBootstrapDialog) {
                window.parent.CloseBootstrapDialog("取消");
            }
        }
    </script>
</head>
<body style="">
    <form id="cc">
    <table style="border: 0px; width: 99%;table-layout: fixed;">
        <tr>
            <td>
                <div id="searchDiv" style='text-align: left;'>
                    <input type="text" id="TB_Key" value="" class="keyWordInput" style="width: 30%;display:inline" placeholder="请输入关键字进行搜索"/>
                    <a href="#"class="btn btn-primary btn-sm" style="margin-left:20px" id="search_btn" onclick="Search()">查询</a>
                    <a href="#"class="btn btn-primary btn-sm" style="margin-left:20px" id="A1" onclick="BtnOK()">确定</a>
                    <input id="hiddenText" type="text" style="display:none" />
                </div>
            </td>
        </tr>
        <tr>
            <td style="border: 1px #FF8000 solid;">
                <div id="tableContent" style="overflow:hidden;">
                    <div>
                        <table class="table" id='jsonDataTable'></table>
                    </div>
                    <div style="text-align: left;">
                        <ul id="examplePagetions"></ul>
                    </div>
                </div>
            </td>
        </tr>
        
    </table>

    <!--杨玉慧加   提示信息弹出窗口-->
    <div class="modal fade" id="msgModal" data-backdrop="static">
        <div class="modal-dialog" >
            <div class="modal-content" style="border-radius: 0px;">
                <div class="modal-header">
                    <button type="button" class="close" id="DalogModelOK1" aria-hidden="true" style="opacity: 1; ">×</button>
                    <h4 class="modal-title">明细表信息</h4>
                </div>
                <div class="modal-body" style="text-align: left; word-wrap: break-word;">
                    <div class="modal-body" style="margin:0px;padding:0px">
                        <iframe style="width:100%;border:0px;height:450px;" id="iframeDtl" ></iframe>
                    </div>
                   
                </div>
            </div>
        </div>
    </div>
    </form>

     
</body>
</html>
